load("@io_bazel_rules_docker//contrib:group.bzl", "group_entry", "group_file")
load("@io_bazel_rules_docker//contrib:passwd.bzl", "passwd_entry", "passwd_file")
load("@rules_oci//oci:defs.bzl", "oci_image")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

oci_image(
    name = "kubevirt-testing-base",
    architecture = select({
        "@io_bazel_rules_go//go/platform:linux_arm64": "arm64",
        "@io_bazel_rules_go//go/platform:linux_s390x": "s390x",
        "//conditions:default": "amd64",
    }),
    os = "linux",
    tars = select({
        "@io_bazel_rules_go//go/platform:linux_arm64": [
            "//rpm:testimage_aarch64",
            ":passwd-tar",
        ],
        "@io_bazel_rules_go//go/platform:linux_s390x": [
            "//rpm:testimage_s390x",
            ":passwd-tar",
        ],
        "//conditions:default": [
            "//rpm:testimage_x86_64",
            ":passwd-tar",
        ],
    }),
    visibility = ["//visibility:public"],
)

passwd_entry(
    name = "root-user",
    gid = 0,
    home = "/root",
    info = "root",
    shell = "/bin/bash",
    uid = 0,
    username = "root",
)

passwd_entry(
    name = "nginx-user",
    gid = 101,
    home = "",
    shell = "/bin/bash",
    uid = 101,
    username = "nginx",
)

passwd_file(
    name = "passwd",
    entries = [
        ":nginx-user",
        ":root-user",
    ],
)

group_entry(
    name = "nginx-group",
    gid = 101,
    groupname = "nginx",
)

group_entry(
    name = "root-group",
    gid = 0,
    groupname = "root",
)

group_file(
    name = "group",
    entries = [
        ":nginx-group",
        ":root-group",
    ],
)

pkg_tar(
    name = "passwd-tar",
    srcs = [
        ":group",
        ":passwd",
    ],
    mode = "0644",
    package_dir = "etc",
    visibility = ["//visibility:public"],
)
